package com.shengyijie.util;

import com.shengyijie.activity.share.ShareConstant;
import com.shengyijie.activity.tab.AboutActivity;
import com.shengyijie.model.object.baseobject.GuesstBook;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
 

public class DataStore {
	
	
	public static String fileName = "data_store";
	
	public static void store(Activity activity, int type,String content) {
		SharedPreferences settings = activity.getSharedPreferences(fileName, Context.MODE_PRIVATE);
		
		SharedPreferences.Editor editor = settings.edit();
		
		if(type==AboutActivity.Page_Help){
			editor.putString("help", content); 
		}else if(type==AboutActivity.Page_About){
			editor.putString("about", content); 	
		}else if(type==AboutActivity.Page_Contact){
			editor.putString("contact", content); 
		}
		 
		
		editor.commit();		
	}
	
	public static void storeMessage(Activity activity, String type,String content) {
		SharedPreferences settings = activity.getSharedPreferences(fileName, Context.MODE_PRIVATE);
		SharedPreferences.Editor editor = settings.edit(); 
	    editor.putString(type, content);  
		editor.commit();		
	}
	
	public static GuesstBook fetchMessage(Activity activity) {
		SharedPreferences settings = activity.getSharedPreferences(fileName, Context.MODE_PRIVATE);
		GuesstBook content = new GuesstBook();   
			content.setName(settings.getString("name", "")); 
			content.setMobile(settings.getString("mobile", "")); 
			content.setEmail(settings.getString("email", "")); 
			content.setAddress(settings.getString("address", "")); 
			content.setContent(settings.getString("content", "")); 
		 
		return content;
	}
	
	public static String fetch(Activity activity,int type) {
		SharedPreferences settings = activity.getSharedPreferences(fileName, Context.MODE_PRIVATE);
		String content = null;  
		if(type==AboutActivity.Page_Help){
			content = settings.getString("help", ""); 
		}else if(type==AboutActivity.Page_About){
			content = settings.getString("about", ""); 
		}else if(type==AboutActivity.Page_Contact){
			content= settings.getString("contact", ""); 
		} 
		return content;
	}
	
	public static void clear(Activity activity,int type) {
		SharedPreferences settings = activity.getSharedPreferences(fileName, Context.MODE_PRIVATE);
		
		SharedPreferences.Editor editor = settings.edit();
		
		if(type==ShareConstant.SHARE_SINA){
			editor.putString("sina_token", null);
			editor.putString("sina_token_secret", null);	
		}else if(type==ShareConstant.SHARE_RENREN){
			editor.putString("renren_token", null);
			editor.putString("renren_token_secret", null);	
		}else if(type==ShareConstant.SHARE_TENCNT){
			editor.putString("tencent_token", null);
			editor.putString("tencnet_token_secret", null);	
		}
        editor.commit(); 
	}	
}
